package com.txc.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;
public class MyLocaleResolver  implements LocaleResolver {
    @Override
    public Locale resolveLocale(HttpServletRequest request) {
//        获得前端传入的参数
        String l = request.getParameter("l");
        Locale aDefault = Locale.getDefault();//如果没有就使用默认的
        if (!(StringUtils.isEmpty(l))){
            String[] s = l.split("_");//根据_将参数分割为两个部分 国家和地区
            aDefault = new Locale(s[0],s[1]);
        }
        return aDefault;
    }

    @Override
    public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {

    }
}
